package com.leetcode.partition4;

/**
 * @author `RKC`
 * @date 2021/8/11 10:59
 */
public class LC344反转字符串 {

    public static void reverseString(char[] s) {
        recursion(s, 0, s.length - 1);
    }

    public static void main(String[] args) {
//        char[] s = {'h', 'e', 'l', 'l', 'o'};
        char[] s = {'h', 'a', 'n', 'n', 'a', 'h'};
        reverseString(s);
        System.out.println(s);
    }

    //递归
    private static void recursion(char[] s, int i, int j) {
        if (i >= j || i < 0 || j >= s.length) return;
        char t = s[i];
        s[i] = s[j];
        s[j] = t;
        recursion(s, i + 1, j - 1);
    }

    //双指针法
    private static void doubleIndex(char[] s) {
        int i = 0, j = s.length - 1;
        while (i <= j) {
            char t = s[i];
            s[i] = s[j];
            s[j] = t;
            i++;
            j--;
        }
    }
}
